package de.derhess.projects.pkr.controller
{
	import de.derhess.projects.pkr.models.PKRCourtLawyerCost;
	
	import mx.events.PropertyChangeEvent;

	
	
	/**
	 * released under MIT License (X11)
	 * http://www.opensource.org/licenses/mit-license.php
	 * 
	 * Class  ControllerPKRCourtLawyerCost
	 * 
	 * @author Florian Weil [derhess.de, Deutschland]
	 * @see http://blog.derhess.de
	 */
	public class ControllerPKRCourtLawyerCost
	{
		//--------------------------------------------------------------------------
		//
		//  Class variables
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		private var model:PKRCourtLawyerCost;
		private var controlOwnLawyer:ControllerLawyerCost;
		private var controlEnemyLawyer:ControllerLawyerCost;
		private var controlCourt:ControllerCourtCost;
		
		//--------------------------------------------------------------------------
		//
		//  Initialization
		//
		//--------------------------------------------------------------------------
		public function ControllerPKRCourtLawyerCost(data:PKRCourtLawyerCost)
		{
			model = data;

			this.model.ownLawyer.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,handleNewSum);
			this.model.enemyLawyer.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,handleNewSum);
			this.model.courtCost.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,handleNewSum);
			
			controlOwnLawyer = new ControllerLawyerCost(this.model.ownLawyer);
			controlEnemyLawyer = new ControllerLawyerCost(this.model.enemyLawyer);
			controlCourt = new ControllerCourtCost(this.model.courtCost);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------

		
		//--------------------------------------------------------------------------
		//
		//  Additional getters and setters
		//
		//--------------------------------------------------------------------------
		public function setLawyerFee(value:Number):void
		{
			controlOwnLawyer.setLawyerFee(value);
			controlEnemyLawyer.setLawyerFee(value);
		}
		
		public function setCourtCost(value:Number):void
		{
			controlCourt.setCourtFee(value);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		public function toString():String 
		{
			return "[ControllerPKRCourtLawyerCost] : _model: " + model.toString();	
		}
		//--------------------------------------------------------------------------
		//
		//  API
		//
		//--------------------------------------------------------------------------
		public function setStartValues(lawyerFee:Number = 0, courtFee:Number = 0,vatValue:int = 19):void
		{
			// Set up for the 'eigene Rechtsanwaltkosten' -> nur Instanz ist aktiv
			this.model.ownLawyer.instance1.litigationFee.factor = 1.3;
			this.model.ownLawyer.instance1.litigationFee.baseValue = lawyerFee;
			this.model.ownLawyer.instance1.riseFee.factor = 0;
			this.model.ownLawyer.instance1.riseFee.baseValue = lawyerFee;
			this.model.ownLawyer.instance1.appointmentFee.factor = 1.2;
			this.model.ownLawyer.instance1.appointmentFee.baseValue = lawyerFee;
			this.model.ownLawyer.instance1.conciliationFee.factor = 0;
			this.model.ownLawyer.instance1.conciliationFee.baseValue = lawyerFee;
			this.model.ownLawyer.instance1.expenses.sum = 20;
			this.model.ownLawyer.instance1.otherCost.sum = 0;
			this.model.ownLawyer.instance1.vat.percentage = vatValue;
			controlOwnLawyer.controllerInstance.includeImputeSum = true;
			
			this.model.ownLawyer.appeal1.litigationFee.factor = 0.0;
			this.model.ownLawyer.appeal1.litigationFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal1.riseFee.factor = 0;
			this.model.ownLawyer.appeal1.riseFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal1.appointmentFee.factor = 0;
			this.model.ownLawyer.appeal1.appointmentFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal1.conciliationFee.factor = 0;
			this.model.ownLawyer.appeal1.conciliationFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal1.expenses.sum = 0;
			this.model.ownLawyer.appeal1.otherCost.sum = 0;
			this.model.ownLawyer.appeal1.vat.percentage = vatValue;
			this.model.ownLawyer.appeal1.vat.baseValue = 0;
			controlOwnLawyer.controllerAppeal1.includeImputeSum = false;
			
			this.model.ownLawyer.appeal2.litigationFee.factor = 0.0;
			this.model.ownLawyer.appeal2.litigationFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal2.riseFee.factor = 0;
			this.model.ownLawyer.appeal2.riseFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal2.appointmentFee.factor = 0;
			this.model.ownLawyer.appeal2.appointmentFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal2.conciliationFee.factor = 0;
			this.model.ownLawyer.appeal2.conciliationFee.baseValue = lawyerFee;
			this.model.ownLawyer.appeal2.expenses.sum = 0;
			this.model.ownLawyer.appeal2.otherCost.sum = 0;
			this.model.ownLawyer.appeal2.vat.percentage = vatValue;
			this.model.ownLawyer.appeal2.vat.baseValue = 0;
			controlOwnLawyer.controllerAppeal2.includeImputeSum = false;
			
			// Set up Gegener Anwaltskosten -> nur Instanz 1 ist aktiv
			this.model.enemyLawyer.instance1.litigationFee.factor = 1.3;
			this.model.enemyLawyer.instance1.litigationFee.baseValue = lawyerFee;
			this.model.enemyLawyer.instance1.riseFee.factor = 0;
			this.model.enemyLawyer.instance1.riseFee.baseValue = lawyerFee;
			this.model.enemyLawyer.instance1.appointmentFee.factor = 1.2;
			this.model.enemyLawyer.instance1.appointmentFee.baseValue = lawyerFee;
			this.model.enemyLawyer.instance1.conciliationFee.factor = 0;
			this.model.enemyLawyer.instance1.conciliationFee.baseValue = lawyerFee;
			this.model.enemyLawyer.instance1.expenses.sum = 20;
			this.model.enemyLawyer.instance1.otherCost.sum = 0;
			this.model.enemyLawyer.instance1.vat.percentage = vatValue;
			controlEnemyLawyer.controllerInstance.includeImputeSum = false;
			
			this.model.enemyLawyer.appeal1.litigationFee.factor = 0.0;
			this.model.enemyLawyer.appeal1.litigationFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal1.riseFee.factor = 0;
			this.model.enemyLawyer.appeal1.riseFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal1.appointmentFee.factor = 0;
			this.model.enemyLawyer.appeal1.appointmentFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal1.conciliationFee.factor = 0;
			this.model.enemyLawyer.appeal1.conciliationFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal1.expenses.sum = 0;
			this.model.enemyLawyer.appeal1.otherCost.sum = 0;
			this.model.enemyLawyer.appeal1.vat.percentage = vatValue;
			this.model.enemyLawyer.appeal1.vat.baseValue = 0;
			controlEnemyLawyer.controllerAppeal1.includeImputeSum = false;
			
			this.model.enemyLawyer.appeal2.litigationFee.factor = 0.0;
			this.model.enemyLawyer.appeal2.litigationFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal2.riseFee.factor = 0;
			this.model.enemyLawyer.appeal2.riseFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal2.appointmentFee.factor = 0;
			this.model.enemyLawyer.appeal2.appointmentFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal2.conciliationFee.factor = 0;
			this.model.enemyLawyer.appeal2.conciliationFee.baseValue = lawyerFee;
			this.model.enemyLawyer.appeal2.expenses.sum = 0;
			this.model.enemyLawyer.appeal2.otherCost.sum = 0;
			this.model.enemyLawyer.appeal2.vat.percentage = vatValue;
			this.model.enemyLawyer.appeal2.vat.baseValue = 0;
			controlEnemyLawyer.controllerAppeal2.includeImputeSum = false;
			
			// Set up Gerichtskosten für Instanz 1 ohne Einigung
			this.model.courtCost.instance1.factor = 3.0
			this.model.courtCost.appeal1.factor = 0;
			this.model.courtCost.appeal2.factor = 0;
			controlCourt.setStartValues(courtFee);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Eventhandling
		//
		//--------------------------------------------------------------------------
		private function handleNewSum(e:PropertyChangeEvent):void
		{
			this.model.instanceSum = this.model.ownLawyer.instance1.sum + this.model.enemyLawyer.instance1.sum + this.model.courtCost.instance1.sum;
			this.model.appeal1Sum = this.model.ownLawyer.appeal1.sum + this.model.enemyLawyer.appeal1.sum + this.model.courtCost.appeal1.sum;
			this.model.appeal2Sum = this.model.ownLawyer.appeal2.sum + this.model.enemyLawyer.appeal2.sum + this.model.courtCost.appeal2.sum;

			this.model.allCostSum = this.model.ownLawyer.sum + this.model.enemyLawyer.sum + this.model.courtCost.sum;
			this.model.vatSum = this.model.ownLawyer.vatSum + this.model.enemyLawyer.vatSum;
		}
		//--------------------------------------------------------------------------
		//
		//  Broadcasting
		//
		//--------------------------------------------------------------------------
		
		
	}
}